package com.example.administrator.xxnapp.login;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.administrator.xxnapp.BaseActivity;
import com.example.administrator.xxnapp.R;
import com.example.administrator.xxnapp.bean.UserBean;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ForgetPasswordActivity extends BaseActivity implements IViewPassword{
    private PasswordPresenter mPresenter;
    @BindView(R.id.act_forget_password_ET_Phone)
    EditText mETPhone;
    @BindView(R.id.act_forget_password_ET_Password)
    EditText mETPassword;
    @BindView(R.id.act_forget_password_ET_SurePassword)
    EditText mETSurePassword;

    @Override
    public int getLayoutId() {
        return R.layout.activity_forget_password;
    }

    @Override
    public void initBeforeDatas() {
        mPresenter = new PasswordPresenter(this,new UserBean());
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);
    }

    @Override
    public void setListeners() {
        mImmersionBar.statusBarColor(R.color.base_color).init();
    }

    @OnClick(R.id.act_forget_password_Btn_Submit)
    public void submit(View view){
        if (TextUtils.isEmpty(mETPhone.getText().toString())){
            Toast.makeText(mContext, "请输入您的手机号", Toast.LENGTH_SHORT).show();
        }else if (TextUtils.isEmpty(mETPassword.getText().toString())){
            Toast.makeText(mContext, "请输入您的新密码", Toast.LENGTH_SHORT).show();
        }else if (TextUtils.isEmpty(mETSurePassword.getText().toString())){
            Toast.makeText(mContext, "请输入您的确认密码", Toast.LENGTH_SHORT).show();
        }else if (!mETPassword.getText().toString().equals(mETSurePassword.getText().toString())){
            Toast.makeText(mContext, "确认密码与输入的密码不符，请重新输入", Toast.LENGTH_SHORT).show();
        }else {
            mPresenter.updatePassword(mETPhone.getText().toString(),mETPassword.getText().toString());
        }
    }

    @Override
    public void updatePasswordSuccess() {
        Toast.makeText(mContext, "修改成功", Toast.LENGTH_SHORT).show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                ForgetPasswordActivity.this.finish();
            }
        },1200);
    }

    @Override
    public void updatePasswordError(int resultCode, String message) {
        Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
    }
}
